import { ConfigService } from '../../../core/common/config.service';
import { BaseService } from '../../../core/service/base.service';
import { Injectable } from '@angular/core';
import { Http, Response } from '@angular/http';
import { Observable } from 'rxjs/Rx';
@Injectable()
export class UserInfoService extends BaseService {
  constructor(protected http: Http, protected config: ConfigService) {
    super(http, config);
  }
  public getNodeBandWidth(): Observable<any> {
    const url = this.config.get('wuhan') + 'getDevBandwidth';
    const obj = { 'startdate': '1daysAgo', 'enddate': 'today', convertValue: 1 };
    return this.http.post(url, obj).map((res: Response) => {
      const body = res.json();
      return body;
    });
  }
  public getNodeBandWidthUsed(device, startdate): Observable<any> {
    const url = this.config.get('wuhan') + 'getDeviceTrafficInfo';
    const obj = { device: device, startdate: startdate, 'enddate': 'today' };
    return this.http.post(url, obj).map((res: Response) => {
      const body = res.json();
      return body;
    });
  }
  public getAppData(device, startdate): Observable<any> {
    const url = this.config.get('wuhan') + 'getAppinfo';
    const obj = { device: device, 'startdate': startdate, 'enddate': 'today' };
    return this.http.post(url, obj).map((res: Response) => {
      const body = res.json();
      return body;
    });
  }
  public getNodePosition(custId, nodeCode): Observable<any> {
    const url = this.config.get('url') + '?service=QueryInfoService&method=getNodePosition';
    return this.http.post(url, { custId: custId, nodeCode: nodeCode }).map((res: any) => {
      const body = res.json();
      console.log(JSON.stringify(body));
      return body.info;
    });
  }
}
